//
//  TBRRentPersonMessageC.m
//  TBText
//
//  Created by yy on 2018/4/30.
//  Copyright © 2018年 yy. All rights reserved.
//

#import "TBRRentPersonMessageC.h"

#import "TBRRentPersonMessageCell.h"
#import "TBRHistoryRentPersonCell.h"
#import "TBRHistoryRentPersonEnumCell.h"

#import "TBRMineModel.h"
#import <YYModel.h>
#import "BaseOperation.h"

#import "TBRAddressBookListC.h"
@interface TBRRentPersonMessageC ()<UITableViewDelegate, UITableViewDataSource,TBRRentPersonMessageCellDelegate>
@property (nonatomic,strong)NSMutableArray *dataArray;
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation TBRRentPersonMessageC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    
    //加载数据
    [self loadData];
}

- (void)setupUI {
    //设置导航条
    [self setupNavItem];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [UIView new];
    [self.tableView registerNib:[UINib nibWithNibName:@"TBRRentPersonMessageCell" bundle:nil] forCellReuseIdentifier:@"TBRRentPersonMessageCellId"];
    [self.tableView registerNib:[UINib nibWithNibName:@"TBRHistoryRentPersonCell" bundle:nil] forCellReuseIdentifier:@"TBRHistoryRentPersonCellId"];
    [self.tableView registerNib:[UINib nibWithNibName:@"TBRHistoryRentPersonEnumCell" bundle:nil] forCellReuseIdentifier:@"TBRHistoryRentPersonEnumCellId"];
}

- (void)setupNavItem {
    self.titleText = @"乘车人信息";
    [self ISG_NavigationBarRightBarWithTitle:@"确认" andAction:@selector(sureBtnClick)];
}

- (void)sureBtnClick {
    [[BaseOperation shareManager] alertShow:self Message:@"是否要提交数据"];
    __weak typeof(self) weakSelf = self;
    [BaseOperation shareManager].actionSure = ^{
        //发送网络数据--
        [weakSelf.navigationController popViewControllerAnimated:YES];
    };
}
#pragma mark - 返回组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

#pragma mark - 返回行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return section == 0 ? 1 : 3;
}

#pragma mark - 返回每行内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //自定义cell
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[self getIdentifier:indexPath] forIndexPath:indexPath];
    [self setupCell:cell indexPath:indexPath];
    return cell;
}

- (NSString *)getIdentifier:(NSIndexPath *)indexPath {

    NSString *iden = @"TBRRentPersonMessageCellId";
    if (indexPath.section == 0) {
        iden = @"TBRRentPersonMessageCellId";
    }else if (indexPath.row == 0){
        iden = @"TBRHistoryRentPersonCellId";
    }else {
        iden = @"TBRHistoryRentPersonEnumCellId";
    }
    return iden;
}

- (void)setupCell:(UITableViewCell *)cell indexPath:(NSIndexPath *)indexPath {
//#import "TBRRentPersonMessageC.h"
//#import "TBRHistoryRentPersonCell.h"
//#import "TBRHistoryRentPersonEnumCell.h"
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.section == 0) {
        TBRRentPersonMessageCell *cellPersonM = (TBRRentPersonMessageCell *)cell;
        cellPersonM.delegate = self;
    }else if(indexPath.row == 0){
        TBRHistoryRentPersonCell *firstRentPerson = (TBRHistoryRentPersonCell *)cell;
    }else {
        TBRHistoryRentPersonEnumCell *historyRentPersonEnumCell = (TBRHistoryRentPersonEnumCell *)cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {return 315;}
    return indexPath.row == 0 ? 87 : 47;
}

- (void)personMessageCellAddressBookBtnClick {
    TBRAddressBookListC *addressBookListC = [[TBRAddressBookListC alloc] init];
    
    //点击确定后数据取回来重新刷新界面
    
    [self.navigationController pushViewController:addressBookListC animated:YES];
}


// MARK: - 加载数据
- (void)loadData {
    [self loadLocalData];
    [self loadNetData];
}
// MARK: - 本地数据
- (void)loadLocalData {
    self.dataArray = [NSMutableArray array];
    NSArray *tmpArray = @[
                          @[@{@"messageId":@"userName",@"imageName":@"",@"titleName":@"用户名",
                              @"detailName":@"丁晓龙"},@{@"messageId":@"userName",@"imageName":@"",@"titleName":@"用户名",@"detailName":@"丁晓龙"}],
                          @[@{@"messageId":@"phoneNum",@"imageName":@"",@"titleName":@"手机",@"detailName":@"13373633086"}],
                          @[@{@"messageId":@"password",@"imageName":@"",@"titleName":@"登录密码",@"detailName":@"未设置"},
                            @{@"messageId":@"payType",@"imageName":@"",@"titleName":@"支付方式",@"detailName":@"我的客服"},]
                          ];
    
    for (NSArray *tmpEnumArray in tmpArray) {
        NSArray *tmpModelArray = [NSArray yy_modelArrayWithClass:[TBRMineInfoBasicModel class] json:tmpEnumArray];
        [self.dataArray addObject:tmpModelArray];
    }
    
}

// MARK: - 获取网络数据-----
- (void)loadNetData {
    
}
@end
